if (typeof $WH == 'undefined') { // Local
  var $WH = {};
}

/**
* Helper for managing sessionStorage.
*
* @type {sessionStorage}
*/
$WH.sessionStorage = {
  /**
  * Test if sessionStorage is supported and usable.
  *
  * @returns boolean
  **/
  isSupported: function() {
    var supported;
    try {
      supported = 'sessionStorage' in window && window['sessionStorage'] !== null;
    } catch (e) {
      supported = false;
    }

    if (supported) {
      try {
        sessionStorage.setItem('test', '123');
        supported = sessionStorage.getItem('test') == '123';
        sessionStorage.removeItem('test');
      } catch (e) {
        supported = false;
      }
    }

    $WH.sessionStorage.isSupported = (function(supported) {
      return supported;
    }).bind(null, supported);
    return supported;
  },

  /**
  * Sets a session storage variable
  *
  * @params key
  * @params value
  */
  set: function(key, value) {
    if (!$WH.sessionStorage.isSupported()) {
      return;
    }

    sessionStorage.setItem(key, value);
  },
  /**
  * Gets a session storage variable
  *
  * @params key
  * @returns *
  */
  get: function(key) {
    if (!$WH.sessionStorage.isSupported()) {
      return;
    }

    return sessionStorage.getItem(key);
  },
  /**
  * Deletes a session storage variable
  *
  * @params key
  */
  remove: function(key) {
    if (!$WH.sessionStorage.isSupported()) {
      return;
    }

    sessionStorage.removeItem(key);
  }
};
